package com.ericpol.page;

import static org.testng.Assert.assertTrue;
import java.util.NoSuchElementException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import com.ericpol.selenium.SeleniumBase;


class Page extends SeleniumBase {

        protected WebDriver driver;

        public Page(WebDriver driver) {
                this.driver = driver;
        }

        protected void openUrl(String  baseUrl) {
            driver.get(baseUrl);
	    }
	
	    protected void findAndClick(By by) {
	            driver.findElement(by).click();
	    }
	    
	    protected void insertText(By by, String text) {
	    	WebElement element = driver.findElement(by);
	    	element.clear();
	    	element.sendKeys(text);
	    }
	    
	    protected void assertTextPresent(String expected) {
	    	assertTrue(driver.getPageSource().contains(expected));
	    }
	    
	    protected boolean isPresentText(By by) {
	    	try {
	    		driver.findElement(by);
	    		return true;
	    	} catch (NoSuchElementException e) {
	    		return false;
	    	}
	    }
}

